package dryven.unittest;

import java.text.MessageFormat;
import java.util.Calendar;
import java.util.Date;

import dryven.i18n.MessageFormatTranslator;
import dryven.i18n.TranslationSource;
import dryven.i18n.Translator;
import junit.framework.TestCase;

public class TranslatorTestCase extends TestCase {
	public void testTranslator() {
		TranslationSource source = new TranslationSource() {
			@Override
			public String getTranslationFormatString(String key) {
				if(key.equals("invalid_email")) {
					return "The e-mail address {0} is not valid.";
				}
				if(key.equals("invalid_date")) {
					return "The date {0,date,short} is not valid.";
				}
				return null;
			}
		};
		Translator tr = new MessageFormatTranslator(source);
		assertTrue(tr.translate("invalid_email","bruno@saltwater.be").equals("The e-mail address bruno@saltwater.be is not valid."));
		assertTrue(tr.translate("invalid_date",new Date(1273856422000l)).equals("The date 14-5-10 is not valid."));
		assertTrue(tr.translate("nonexistentkey","").equals("???nonexistentkey???"));
	}
}
